<?php

/**
 * LoginForm class.
 * LoginForm is the data structure for keeping
 * user login form data. It is used by the 'login' action of 'SiteController'.
 */
class ForgetPassForm extends CFormModel
{

    public $mobile;
    public $verifyCode;
    public $password;

    /**
     * Declares the validation rules.
     * The rules state that username and password are required,
     * and password needs to be authenticated.
     */
    public function rules()
    {
        return array(
            array('mobile, verifyCode,password', 'required'),
            array('verifyCode','checkCode'),
            array('password','length','is' => 32,'message'=>'密码长度不对'),
            array('password','checkPass'),
        );
    }
    /**
     * Declares attribute labels.
     */
    public function attributeLabels()
    {
        return array(
            'mobile'     => '手机号',
            'verifyCode' => '验证码',
            'password'   => '密码',
       );
    }

    public function checkCode()
    {
        if(Yii::app()->cache2->get('get_back_password'.$this->mobile)!=$this->verifyCode)
            $this->addError('verifyCode','短信验证码不正确');
    }

    public function checkPass()
    {
        if(Helper::checkIsSimplePass($this->password))
            $this->addError('password','密码过于简单，请使用安全系数更高的密码');
    }
}
